package cn.powertime.evaluation;

import java.util.Date;

public class DateTransformHourUtil {

    public static String transform(Date date){
        String str;
        long now = System.currentTimeMillis();

        //long time = dateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
        long time = date.getTime();

        int m = (int) ( now - time )/1000/60;
        if(m < 1){
            str = "刚刚";
        } else if(m < 60){
            str = m + "分钟前";
        } else if(m >= 60 && m < 1440 ) {
            int h = m/60;
            str = h + "小时前";
        } else if(m >= 1440 && m < 2880) {
            int d = m/60/24;
            str = d + "天前";
        } else {
            str = DateFormatUtil.formatDate(DateFormatUtil.YYYY_MM_DD_HH_MM_SS,time);
        }
        return str;
    }

//    public static void main(String[] args) {
//        System.out.println(transform(LocalDateTime.parse("2019-10-09 11:19:45", DateTimeFormatter.ofPattern(DateFormatUtil.YYYY_MM_DD_HH_MM_SS))));
//    }

}
